home *** CD-ROM | disk | FTP | other *** search
- Path: unix.sri.com!usenet
- From: mklenk@updike.sri.com (Mark Klenk)
- Newsgroups: comp.lang.c
- Subject: Re: StandardIn
- Date: 5 Feb 1996 17:28:26 GMT
- Organization: Nuance Communications
- Message-ID: <4f5enq$6mg@unix.sri.com>
- References: <DMB5AC.2tD@nyhp02.serigate.philips.nl>
- Reply-To: mklenk@updike.sri.com
- NNTP-Posting-Host: 204.75.161.40
-
- Arjan Geertsma wrote:
- >
- >Is there a simple way to change a program wich uses a normal input file to use
- >stdin for its input?
-
- Yes, there is.
-
- #include <stdio.h>
-
- int main(int argc, char * argv[])
- {
- FILE * fin = stdin;
-
- if (2 <= argc) {
- fin = fopen(argv[1], "rb");
- if (NULL == fin) {
- fprintf(stderr, "Unable to open \"%s\" for reading.\n",
- argv[1]);
- return EXIT_FAILURE;
- }
- }
-
- /* Do important stuff here. */
-
- if (stdin != fin) {
- fclose(fin);
- }
- return EXIT_SUCCESS;
- }
-
- ---
-
- mklenk@coronacorp.com (Mark Klenk)
-
-
-
-